-
-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue 2968 by adding a new pragma(framework) #10615
Conversation
Thanks for your pull request and interest in making D better, @benjones! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#10615" |
…lags to the link command on macos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Should this pragma only be available on macOS?
-
I’m not sure if this is a good idea at all. GDC won’t support it since it doesn’t support
pragma(lib)
assert(length == array.length); | ||
foreach (i, x; array) | ||
{ | ||
assert(x == cast(ulong) CFArrayGetValueAtIndex(cfa, i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’re storing int
not ulong
on the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am? The array is declared as ulong[5]
above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was only looking at the array literal. My bad.
Furthermore, even if GDC did support it, there are still shortcomings to the pragma() approach that means it still won't work if you are linking to a project/package that has |
Thanks for the feedback. If people decide that this isn't a good idea, then we should probably close the bug report wontfix. Is pragma(lib) useful in gdc? It looks like only when the libs can be stored in the actual object file, but I don't know which formats actually support that. @adamdruppe seemed enthusiastic about this before... do you still feel that way? |
Yes, I am still for it. Just because it doesn't work everywhere - even if it doesn't work most places - doesn't mean it isn't useful where it does work, and it still serves as formal, machine-readable documentation in the cases where it doesn't work. |
Needs a PR for the spec as well: https://dlang.org/spec/pragma.html. |
Another note, since this writes the framework to the moduleDeps file, the framework info could be picked up by a build system tool |
+1. Extending the weak |
Just put a note in the documentation saying the result is implementation specific. Don't let the perfect be the enemy of the good. |
I'm also concerned about this. |
On Sun, Dec 01, 2019 at 06:30:59PM -0800, Mathias LANG wrote:
`pragma(lib)` sounded like a good idea, but in practice didn't pan out so well.
I find it enormously useful in practice and use it regularly without any
problem or difficulty.
|
I'll have to defer to those expert on the MacOS as to whether it is useful or not. Do other languages on the Mac support such a mechanism? |
Kind of. Objective-C and Swift supports autolinking of frameworks. Basically you only need to import the framework and it will automatically be linked when building. I think Clang implements this using |
@kinke Linker directives can be embedded in Mach-O files, see my previous comment: #10615 (comment). |
Well if it can in a suitable manner (embedded strings as additional linker cmdline arguments?), then I think it's a no-brainer to extend existing |
[Btw, LLD 9 added support for embedded library dependencies in ELF object files, suitable for |
As far as I can see it will embed strings as additional linker command line arguments. Here's an example of one of the load commands from the object dumper:
To me, that looks very much like a linker command line argument. The comment in the header file says:
|
Okay perfect, that's analogous to MS COFF linker directives then. Then I'd propose either |
Do you think there's an advantage to having the user write out the whole linker command rather than using the proposed syntax? If we use linkerDirective, the user would have to static if it out on "not macos" builds, whereas pragma(framework) might only be examined on macos. I'll defer to the experts, but I kind of like the pragma(framework) syntax. |
Yes, I absolutely prefer having one generic way of expressing the same thing (linker flags embedded in object files) for multiple targets over a ever-growing family of target- and compiler-specific pragmas. |
I can live with linkerDirective instead of pragma framework if it actually works. |
OK, I'll look into that approach. Is there already code in the machobj backend for LC_LINKER_OPTION stuff or will that need to be added? |
No, that needs to be added. You can look at one of my pull requests how to add a new load command: #10476. |
I had to do a double take, apparently I completely missed the introduction of that pragma. |
I wrote such a thing for gdc too, which writes the data into a custom section, then all objects are scanned by the driver. From what I remember, it didn't extend to linking against D libraries (neither static nor dynamic) that may have this section embedded in. As the linked patch for the LLVM linker, I assume you won't have that problem? |
At least I don't plan to do any scanning of objects/libraries in the LDC driver; for Posix targets, we simply invoke gcc or clang for linking, so the plan is to let them take care of everything, even if that means that this special section might only work in combination with clang and LLD for now. |
This is implemented for LDC now in ldc-developers/ldc#3259. It includes a small frontend patch for
=> |
Which just adds appropriate flags to the linker command.
@jacob-carlborg I sort of based this off or your old patch. LMK what I overlooked.
I copypasted stuff from pragma(lib) impl. Not sure if it's a good idea to try to unify them or not.
I added this section to json.d. I could only output it if it's not empty or something to reduce the number of tests that need to be updated?